<?php
include("../functions.php");
include("../libs/smarty.class.php");

$smarty = new Smarty();

if(isset($_POST['login']))
    {
        $email = $_POST['email'];
        $password = md5($_POST['password']);
        
        $table = $_POST['choose'];
        if($table=='student'){
            $table = 'user_student';
        }else{
            $table = 'user_company';
        }

        $sql=mysql_query("SELECT id FROM `$table` WHERE email='$email' and password='$password'");
        $row=mysql_fetch_array($sql);
        $count=mysql_num_rows($sql);
        $id = $row['id'];

        if($count == 1)
            {
            session_register("user");
            $_SESSION['user_email'] = $email;
            $_SESSION['user_id'] = $id;
            $_SESSION['user_type'] = $table;
            if($table == 'user_company'){
                $company = array();
                $company = getRow("id,email,name,address,phone,site","$id","$table");
                $_SESSION['company_info'] = $company;
            }
            if($table =='user_student'){
                $student = array();
                $student = getRow("id,email,name,surname,album_nr,faculty_id,specialization_id,practice_id","$id","$table");
                $_SESSION['student_info'] = $student;
            }
            echo '
            <script type="text/javascript">
                location.href="../index.php";
            </script> ';
        }
        else{
            $info = getInfo(7);
            echo'
            <script type="text/javascript">
                location.href="../index.php";
                alert("'.$info.'");
            </script> ';
        }
    }
?>
